package com.dsj.gxrd.modules.controller.book;

import com.dsj.gxrd.modules.book.domain.entity.RdBookCategory;
import com.dsj.gxrd.modules.book.domain.vo.RdBookCatTree;
import com.dsj.gxrd.modules.book.service.IRdBookCategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

import java.util.List;

/**
 * @author ruoyi
 * @date 2023-09-11
 */
@Api(tags = "书香人大推荐书籍分类")
@RestController
@RequestMapping("/book/category")
public class RdBookCategoryController extends BaseController {
    @Autowired
    private IRdBookCategoryService rdBookCategoryService;

    //@RequiresPermissions("book:category:list")
    @GetMapping("/list")
    public TableDataInfo list(RdBookCategory rdBookCategory) {
        startPage();
        List<RdBookCategory> list = rdBookCategoryService.selectRdBookCategoryList(rdBookCategory);
        return getDataTable(list);
    }

    //@RequiresPermissions("book:category:query")
    @GetMapping(value = "/{rdBookCatId}")
    public AjaxResult getInfo(@PathVariable("rdBookCatId") Long rdBookCatId) {
        return success(rdBookCategoryService.selectRdBookCategoryByRdBookCatId(rdBookCatId));
    }

    /**
     * 获取指定分类id下的所有树形节点结构
     */
    //@RequiresPermissions("book:category:tree")
    @GetMapping("/category/{rdBookCatId}")
    public AjaxResult getCategoryTree(@PathVariable Long rdBookCatId) {
        List<RdBookCatTree> tree = rdBookCategoryService.getCategoryTree(rdBookCatId);
        return AjaxResult.success(tree);
    }
}
